//
//  BackgroundLayer.h
//  SCRAP_ObjC
//
//  Created by Capstone Design Fall 2010 on 10/18/10.
//  Copyright 2010 Thunderwear. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <GameKit/GameKit.h>
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "Card.h"
#import "StackData.h"
#import "Player.h"
#import "StackAdditions.h"
#import "iPadSession.h"

#define iPadBGZ 0
#define iPadMGZ 1
#define iPadFGZ 2

@interface BackgroundLayer : CCColorLayer {
    NSMutableArray *cornerPoints;
	NSMutableArray *colors;
	
	NSMutableArray *layout;
	
	CGFloat cornerRadius;
	
	CCSprite *background;
	
	CCLabel *lockLabel;
	
	StackData *stackLayout;
	
	CGSize size;
	CGPoint center;
	
	CGPoint touchOffset;
	
	CCColorLayer *opacityLayer;
	
	NSMutableArray	*playerList;
	
	iPadSession *gameSession;
	
	//Menu stuff
	bool menuMode;
	//bool scoreMode;
	bool circleIsMoving;
	CCMenu *menu;
	CCMenuItemSprite *startButton;
	int schedPlayers;
	int currentPlayerIndex;
	int currentCircleIndex;
	NSMutableArray *circles;
	NSMutableArray *corners;
	CGPoint movingCirclePreviousPosition;
	NSMutableArray *playerLabels;
	CCLabel *currentPlayerLabel;
	
	NSMutableArray *nameLabels;
	NSMutableArray *nameStrings;
	
	NSMutableArray *cornerScores;
	
	NSMutableArray * cards;
	
	bool playerScheduling;
	int roundLimit;
	int scoreLimit;
	
	int currentRound;
	
	bool gamePlayabe;
	
	float disconnectElapsedTime;
	CCLabel *timerLabel;
	int endGameTimer;
	
	CCMenuItemLabel *endRoundButton;
	CCMenu *endRoundMenu;
	
	NSMutableArray *emptyBacks;
	
	bool cornerChoosing;
	
	bool patDebugging;
}
@property (retain) NSMutableArray *nameLabels;
@property (retain) NSMutableArray *nameStrings;
@property (retain) NSMutableArray *emptyBacks;
@property (retain) CCLabel *timerLabel;
@property (retain) CCMenuItemLabel *endRoundButton;
@property (retain) CCMenu *endRoundMenu;
@property int endGameTimer;
@property bool gamePlayable;
@property bool patDebugging;

@property float disconnectElapsedTime;

//@property(nonatomic, retain) GKSession	 *gameSession;
//@property(nonatomic, copy)	 NSString	 *gamePeerId;
@property(retain) NSMutableArray *playerList;

@property (retain) NSMutableArray *cornerScores;
@property (retain) CCColorLayer *opacityLayer;
@property bool menuMode;
//@property bool scoreMode;
@property (retain) NSMutableArray *circles;
@property (retain) NSMutableArray *corners;
@property (retain) CCMenu *menu;
@property (retain) CCMenuItemSprite *startButton;
@property int schedPlayers;
@property CGPoint movingCirclePreviousPosition;
@property (retain) NSMutableArray *playerLabels;
@property (retain) CCLabel *currentPlayerLabel;
@property bool playerScheduling;
@property int roundLimit;
@property int scoreLimit;
@property int currentRound;
@property bool cornerChoosing;

+(BackgroundLayer*) initWithRoundLimit:(int) limit;
+(BackgroundLayer*) initWithScoreLimit:(int) limit;

//- (void)invalidateSession:(GKSession *)session;

//for debugging
-(void) patDebug;

//initialization helpers
-(void) setUpCorners;
-(void) setUpCircles;
-(void) setUpMenu:(CGPoint)p;
-(void) killMenu;
-(void) killCircles;
-(void) setUpScoreCorners;

//update / interval / scheduled functions
-(void) update:(ccTime)dt;
-(void) updateDisplayedPlayerList:(ccTime)dt;
-(void) endGameCountdown:(ccTime)dt;

//button actions
-(void) startButtonAction;

//helper functions
-(void) setCurrentPlayerLabels:(Player*)player;
-(void) unsetCurrentPlayerLabels;
-(CGPoint) nearestCorner:(CGPoint)p;
-(BOOL) cornerCheck:(CGPoint)p;
-(void) addPlayerToMenu:(Player*)p;
-(void) removePlayerFromMenuByPeerID:(NSString*)peerID;
-(BOOL) cardOnStack:(Card*)c;
-(BOOL) intersectCircle:(CGPoint)a withPointB:(CGPoint)b withRadius:(float)radius;
-(float) distanceBetweenTwoPoints:(CGPoint)a withPointB:(CGPoint)b;
-(CGPoint) directionOfCenter:(CGPoint)p;
-(void) growEffect:(CGPoint) point;

-(void) scaleObject:(id)object withDuration:(float)duration toScale:(float)s;
-(void) scaleObject:(id)object withDuration:(float)duration byScale:(float)s;
-(void) rotateObject:(id)object withDuration:(float)duration toAngle:(float)angle;
-(void) rotateObject:(id)object withDuration:(float)duration byAngle:(float)angle;
-(void) moveObject:(id)object withDuration:(float)duration withPoint:(CGPoint)point;
-(void) tintObject:(id)object withDuration:(float)duration red:(int)red green:(int)green blue:(int)blue;
-(void) fadeObject:(id)object withDuration:(float)duration withOpacity:(int)opacity;

-(void) resetLayout;
-(void) resetGame;

-(BOOL) gameIsOver;
-(Player*) getWinner;

-(void) updateCount:(int)rcount forPeer:(NSString*)peer;

//for networking
-(void) returnCard:(Player*)player;
-(void) acceptCard:(Player*)player;
-(void) setPicker:(iPadSession*)sesh;
-(void) sendColor:(Player*)player withPortal:(CCSprite*)p;
-(void) session:(iPadSession*)sesh newPlayer:(Player*)playa;
+(void) FalseScoreMode;

@end
